/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.openjawtech.xscraper.scraper.util;

import java.io.File;
import com.openjawtech.xscraper.scraper.exception.ConfigurationException;

/**
 *
 * @Created on 15-Apr-2009, 17:28:21
 * @author Wenbo.Sun
 */
public class FileUtil {


    public static void makeDir(String path, String name) throws ConfigurationException {
        File parent = new File(path);
        if(!parent.exists())
            throw new ConfigurationException("path is not existed");
        if(!parent.isDirectory()){
            throw new ConfigurationException("path is not a dir");
        }
        File dir = new File(parent.getPath() + "/" + name);
        if(dir.exists())
            throw new ConfigurationException("dir is existed");
        dir.mkdir();
    }

    public static boolean isExisted(File file) {
        if (file.exists())
            return true;
        return false;
    }

    public static boolean isExisted(String path) {
        File file = new File(path);
        return isExisted(file);
    }

    public static boolean isFolderAndExisted(File file) {
        if (isExisted(file)){
            if (file.isDirectory())
                return true;
        }
        return false;
    }

    public static boolean isFolderAndExisted(String path) {
        File file = new File(path);
        return isFolderAndExisted(file);
    }

}
